<!-- 去租客 -->
<template>
  <div class="box">
    <div class="box-header">
      <div @click="fanhui">《返回</div>
      <div>登录</div>
      <div></div>
    </div>
    <div class="box-bbody">
      <div class="box-box1">
        <van-form validate-first @failed="onFailed">
          <!-- 通过 pattern 进行正则校验 -->
          <van-field
            v-model="value1"
            name="pattern"
            placeholder="账号"
            :rules="[{ pattern, message: '请输入正确账号' }]"
          />

          <!-- 通过 validator 进行异步函数校验 -->
          <van-field
            v-model="value3"
            name="asyncValidator"
            placeholder="密码"
            :rules="[
              { validator: asyncValidator, message: '请再次输入的密码' },
            ]"
          />
          <div style="margin: 16px" @click="biaobaio">
            <van-button round block type="info" native-type="submit"
              >提交</van-button
            >
          </div>
        </van-form>
      </div>
    </div>
  </div>
</template>

<script>
import { Toast } from "vant";
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      value1: "",
      value3: "",
      pattern: /\d{6}/,
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    biaobaio() {
      this.$router.push("/Biaoge");
    },
    //返回fanhui
    fanhui() {
      this.$router.push("/Home");
    },
    // 校验函数返回 true 表示校验通过，false 表示不通过
    validator(val) {
      return /1\d{10}/.test(val);
    },
    // 异步校验函数返回 Promise
    asyncValidator(val) {
      return new Promise((resolve) => {
        Toast.loading("验证中...");

        setTimeout(() => {
          Toast.clear();
          resolve(/\d{6}/.test(val));
        }, 1000);
      });
    },
    onFailed(errorInfo) {
      console.log("failed", errorInfo);
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
};
</script>
<style lang='scss' scoped>
.box {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: pink;
  font-size: 12px;
}
.box-header {
  width: 100%;
  height: 1rem;
  background: #fff;
  border-bottom: 1px solid #000;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0px 20px;
}
.box-bbody {
  width: 100%;
  flex: 1;
  overflow-x: hidden;
  background: rgb(255, 255, 255);
  display: flex;
  flex-direction: column;
}
.box-box1 {
  width: 100%;
  height: 5rem;
  background: rgb(255, 255, 255);
}
</style>